home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / newmat08.zip / CONTROLW.H < prev    next >
C/C++ Source or Header  |  1995-01-11  |  2KB  |  49 lines

  1. //$$ controlw.h                Control word class
  2.  
  3. #ifndef CONTROL_WORD_LIB
  4. #define CONTROL_WORD_LIB 0
  5.  
  6. // for organising an int as a series of bits which indicate whether an
  7. // option is on or off.
  8.  
  9. class ControlWord
  10. {
  11. protected:
  12.    int cw;                                      // the control word
  13. public:
  14.    ControlWord() : cw(0) {}                     // do nothing
  15.    ControlWord(int i) : cw(i) {}                // load an integer
  16.  
  17.       // select specific bits (for testing at least one set)
  18.    ControlWord operator*(ControlWord i) const
  19.       { return ControlWord(cw & i.cw); }
  20.    void operator*=(ControlWord i)  { cw &= i.cw; }
  21.  
  22.       // set bits
  23.    ControlWord operator+(ControlWord i) const
  24.       { return ControlWord(cw | i.cw); }
  25.    void operator+=(ControlWord i)  { cw |= i.cw; }
  26.  
  27.       // reset bits
  28.    ControlWord operator-(ControlWord i) const
  29.       { return ControlWord(cw - (cw & i.cw)); }
  30.    void operator-=(ControlWord i) { cw -= (cw & i.cw); }
  31.  
  32.       // check if all of selected bits set or reset
  33.    Boolean operator>=(ControlWord i) const { return (cw & i.cw) == i.cw; }
  34.    Boolean operator<=(ControlWord i) const { return (cw & i.cw) == cw; }
  35.  
  36.       // flip selected bits
  37.    ControlWord operator^(ControlWord i) const
  38.       { return ControlWord(cw ^ i.cw); }
  39.    ControlWord operator~() const { return ControlWord(~cw); }
  40.  
  41.       // convert to integer
  42.    int operator+() const { return cw; }
  43.    int operator!() const { return cw==0; }
  44.    FREE_CHECK(ControlWord)
  45. };
  46.  
  47.  
  48. #endif
  49.